package com.example.bitmaploading;

import java.lang.reflect.Field;

import com.example.bitmaploading.utils.LogUtils;

import android.app.Application;
import android.util.DisplayMetrics;

public class BLApplication extends Application {

  /** 屏幕宽高，标题栏高度 */
  private int displayWidth;
  private int displayHeight;
  private int statusBarHeight;
  
  @Override
  public void onCreate() {
    getParameters();
    super.onCreate();
  }

  /**
   * 获取屏幕宽高等参数
   */
  private void getParameters()
  {
    //DisplayMetrics displayMetrics = new DisplayMetrics();
    //getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    
    DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
    displayWidth = displayMetrics.widthPixels;
    displayHeight = displayMetrics.heightPixels;
    //
    Class<?> c = null;
    Object obj = null;
    Field field = null;
    int x = 0, sbar = 0;
    try
    {
      c = Class.forName("com.android.internal.R$dimen");
      obj = c.newInstance();
      field = c.getField("status_bar_height");
      x = Integer.parseInt(field.get(obj).toString());
      sbar = getResources().getDimensionPixelSize(x);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    statusBarHeight = sbar;
    
    LogUtils.showLog(getApplicationContext(), "dw --> " + displayWidth + "\ndh --> " + displayHeight + "\nsh --> " + statusBarHeight);
  }
  
  public int getDisplayWidth() {
    return displayWidth;
  }

  public int getDisplayHeight() {
    return displayHeight;
  }

  public int getStatusBarHeight() {
    return statusBarHeight;
  }

}
